﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Entity;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using SchoolProject2012.Areas.Professeur.Models;

namespace SchoolProject2012.Areas.Professeur.Controllers
{
    public class QuestionEvalController : Controller
    {
        private ProfesseurSchoolProjectBddEntities db = new ProfesseurSchoolProjectBddEntities();

        //
        // GET: /Professeur/QestionEval/

        public ActionResult Index(int id)
        {
            var questioneval = db.QUESTIONEVAL.Where(x => x.IDEVAL == id).ToList();
            //var questioneval = db.QUESTIONEVAL.Include("EVALUATION");
            return View(questioneval.ToList());
        }

        //
        // GET: /Professeur/QestionEval/Details/5

        public ActionResult Details(int id = 0)
        {
            QUESTIONEVAL questioneval = db.QUESTIONEVAL.Single(q => q.IDQUESTEVAL == id);
            if (questioneval == null)
            {
                return HttpNotFound();
            }
            return View(questioneval);
        }

        //
        // GET: /Professeur/QestionEval/Create

        public ActionResult Create()
        {
            ViewBag.IDEVAL = new SelectList(db.EVALUATION, "IDEVAL", "LIBEVAL");
            return View();
        }

        //
        // POST: /Professeur/QestionEval/Create

        [HttpPost]
        public ActionResult Create(QUESTIONEVAL questioneval)
        {
            if (ModelState.IsValid)
            {
                db.QUESTIONEVAL.AddObject(questioneval);
                db.SaveChanges();
                return RedirectToAction("Index", new{ id = questioneval .IDEVAL});
            }
         
            ViewBag.IDEVAL = new SelectList(db.EVALUATION, "IDEVAL", "LIBEVAL", questioneval.IDEVAL);
            return View(questioneval);
        }

        //
        // GET: /Professeur/QestionEval/Edit/5

        public ActionResult Edit(int id = 0)
        {
            QUESTIONEVAL questioneval = db.QUESTIONEVAL.Single(q => q.IDQUESTEVAL == id);
            if (questioneval == null)
            {
                return HttpNotFound();
            }
            ViewBag.IDEVAL = new SelectList(db.EVALUATION, "IDEVAL", "LIBEVAL", questioneval.IDEVAL);
            return View(questioneval);
        }

        //
        // POST: /Professeur/QestionEval/Edit/5

        [HttpPost]
        public ActionResult Edit(QUESTIONEVAL questioneval)
        {
            if (ModelState.IsValid)
            {
                db.QUESTIONEVAL.Attach(questioneval);
                db.ObjectStateManager.ChangeObjectState(questioneval, EntityState.Modified);
                db.SaveChanges();
                return RedirectToAction("Index", new { id = questioneval.IDEVAL });
            }
            ViewBag.IDEVAL = new SelectList(db.EVALUATION, "IDEVAL", "LIBEVAL", questioneval.IDEVAL);
            return View(questioneval);
        }

        //
        // GET: /Professeur/QestionEval/Delete/5

        public ActionResult Delete(int id = 0)
        {
            QUESTIONEVAL questioneval = db.QUESTIONEVAL.Single(q => q.IDQUESTEVAL == id);
            if (questioneval == null)
            {
                return HttpNotFound();
            }
            return View(questioneval);
        }

        //
        // POST: /Professeur/QestionEval/Delete/5

        [HttpPost, ActionName("Delete")]
        public ActionResult DeleteConfirmed(int id)
        {
            QUESTIONEVAL questioneval = db.QUESTIONEVAL.Single(q => q.IDQUESTEVAL == id);
            db.QUESTIONEVAL.DeleteObject(questioneval);
            db.SaveChanges();
            return RedirectToAction("Index", new { id = questioneval.IDEVAL });
        }

        protected override void Dispose(bool disposing)
        {
            db.Dispose();
            base.Dispose(disposing);
        }
    }
}